/*
 * Copyright (c) 2016 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.serv.shop.api.impl;

import com.jnzc.ocr.common.bean.PageResult;
import com.jnzc.ocr.common.utils.ValidateUtils;
import com.jnzc.ocr.serv.shop.api.ShopSupplierCategoryApi;
import com.jnzc.ocr.serv.shop.entity.ShopSupplierCategory;
import com.jnzc.ocr.serv.shop.entity.ShopSupplierCategory;
import com.jnzc.ocr.serv.shop.filter.ShopSupplierCategoryFilter;
import com.jnzc.ocr.serv.shop.service.ShopSupplierCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangcm
 * @version 1.0, 2017/9/13
 */
@RestController
public class ShopSupplierCategoryApiImpl implements ShopSupplierCategoryApi {

    @Autowired
    private ShopSupplierCategoryService shopSupplierCategoryService;

    @Override
    public ShopSupplierCategory find(@RequestParam("id") Long id, @RequestParam("shopId") Long shopId) {
        return shopSupplierCategoryService.find(id, shopId);
    }

    @Override
    public List<ShopSupplierCategory> list(@RequestBody ShopSupplierCategoryFilter filter) {
        return shopSupplierCategoryService.list(filter);
    }

    @Override
    public PageResult<ShopSupplierCategory> search(@RequestBody ShopSupplierCategoryFilter filter, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return shopSupplierCategoryService.search(filter, pageNo, pageSize);
    }

    @Override
    public ShopSupplierCategory save(@RequestBody ShopSupplierCategory param) {
        ValidateUtils.isId(param.getShopId(), "店铺ID");
        ValidateUtils.notEmpty(param.getName(), 20, "店铺名称");
        ShopSupplierCategory obj;
        if(null == param.getId()){
            obj = new ShopSupplierCategory();
            obj.setShopId(param.getShopId());
        }else{
            obj = find(param.getId(), param.getShopId());
        }
        obj.setName(param.getName());
        return shopSupplierCategoryService.save(obj);
    }

    @Override
    public void delete(@RequestParam("id") Long id, @RequestParam("shopId") Long shopId) {
        ShopSupplierCategory obj = find(id, shopId);
        shopSupplierCategoryService.delete(id);
    }
}
